//收藏夹Js文件
let moreProStr = ''

//取出本地商品数据

//获取用户的本地存储名称作为购物车名称
let userString = localStorage.getItem('USER')
let userList = JSON.parse(userString)
let nameC = userList.username

let listStr = localStorage.getItem(`Collection+${nameC}`)
let list = JSON.parse(listStr) || []
if (list.lebgth < 1) {
    $('#main').html('收藏夹空空如也~')
} else {
    showProductList(list)
}
//动态加载商品列表
function showProductList(productList) {
    let proStr = productList.map(item => {
        //点击获取商品id
        return `
        <li onclick="toDetail(${item.id})">
        <img src="${item.url}"
            alt="">
        <p>${item.name}</p>
        <p class="clearfix">
            <span class="fl">淘宝</span>
            <span class="fr">包邮</span>
        </p>
        <p>
            <span>￥${item.price}</span>
            <span>${item.id}人已买</span>
        </p>
        <p onclick="removeCol()" data-index="${item.id}">移除</p>
    </li>`
    }).join('')

    moreProStr += proStr
    $('#list ul').html(moreProStr)
}

//点击移除收藏夹
function removeCol() {
    let id = $(this).attr('data-index')
    console.log(id);
}




//跳转到详情页
function toDetail(id) {
    location.href = '../pages/details.html?id=' + id
}